<!DOCTYPE html>
<html>
<head>
	<script type="text/javascript" src="__PUBLIC__/easyui/jquery.min.js"></script>
	<script type="text/javascript" src="__PUBLIC__/easyui/jquery.easyui.min.js"></script>
	<script type="text/javascript" src="__PUBLIC__/easyui/locale/easyui-lang-zh_CN.js"></script>
	<link rel="stylesheet" type="text/css" href="__PUBLIC__/easyui/themes/gray/easyui.css">
	<link rel="stylesheet" type="text/css" href="__PUBLIC__/easyui/themes/icon.css">
	<script type="text/javascript" src="__PUBLIC__/js/add-tab.js"></script>

</head>
<body>
	
	<div id="tb" style="padding:5px;height:auto">
		<div style="margin-bottom:5px">
			<span>员工工号:</span>
			<input id="employe_work_id" name="employe_work_id" type="text"/>
			<span>姓名:</span>
			<input id="employe_name" name="employe_name" type="text"/>
			<span>部门:</span>
			<select id="employe_department_id">
				<option value="">--请选择部门--</option>
				{$json}
			</select>
			<a href="javascript:void(0);" class="easyui-linkbutton" iconCls="icon-search" onClick="doSearch()">搜索</a>
			<a href="javascript:void(0);" src="__URL__/selectEmploye" class="easyui-linkbutton cs-navi-tab-select" id="select_employe" iconCls="icon-search">查看用户</a>
			<a href="javascript:void(0);" src="__URL__/addEmploye" class="cs-navi-tab easyui-linkbutton" iconCls="icon-employe-add">添加用户</a>
			<a href="javascript:void(0);" class="easyui-linkbutton" id="change_password" iconCls="icon-employe-del">修改密码</a>
			<a href="javascript:void(0);" src="__URL__/editEmploye" class="easyui-linkbutton cs-navi-tab-edit" id="edit_employe" iconCls="icon-employe-edit">编辑用户</a>
			<a href="javascript:void(0);" class="easyui-linkbutton" id="del_employe" iconCls="icon-employe-del">删除用户</a>
		</div>
	</div>
	<table id="tt" title="用户管理" class="easyui-datagrid" style="width:auto;height:auto;" idField="employe_id" pageSize="20" pageList="[20,40,80]" data-options="rownumbers:true,singleSelect:true,url:'__URL__/employeListData',toolbar:'#tb',iconCls:'icon-users'" pagination="true" fitColumns="true" fit="true">
		<thead>
			<tr>
				<th data-options="field:'employe_name',width:150,align:'center'">姓名</th>
				<th data-options="field:'employe_work_id',width:150,align:'center'">工号（用户名）</th>
				<th data-options="field:'employe_sex',width:150,align:'center'">性别</th>
				<th data-options="field:'employe_department_id',width:150,align:'center'">部门</th>
			</tr>
		</thead>
	</table>
	<div id="edit_dlg" class="easyui-dialog" style="width:280px;height:160px;" iconCls="icon-mem-level" closed="true">
        <form  method="post" id="efrms">
            <table cellspacing="0" cellpadding="2">
            	<input type="hidden" name="employe_id"/>
                <tr style="line-height:45px;height: 45px">
                    <td width="100" align="right">新密码：</td>
                    <td width="100">
                    	<input class="employe_password easyui-validatebox" name="employePassword" type="password" data-options="validType:['length[6,30]'],required:true"/>
                    </td>
                </tr>

                <tr style="line-height:25px; height: 25px">
                    <td width="100" align="right">确认密码：</td>
                    <td width="100">
                    	<input class="employe_password_true easyui-validatebox" type="password" validType="equalTo['.employe_password']" data-options="required:true"/>
                    </td>
                </tr>
                
                <tr>
                    <td colspan="2" align='center'>
                        <input type="submit" value="保存"/>
                        <input type="button" onClick="javascript:$('#edit_dlg').dialog('close')" value="取消" />
                    </td>
                </tr>
            </table>
        </form>
    </div>
	
<script type="text/javascript">
	function doSearch(){
		$('#tt').datagrid('load',{
			employe_work_id: $('#employe_work_id').val(),
			employe_name: $('#employe_name').val(),
			employe_department_id:$('#employe_department_id').val()
		});
	}

	
	$(function(){
		var i=1;
		var j=1;
		$('#tt').datagrid({
			onDblClickRow: function(rowIndex,rowData){
					var $this = $('.cs-navi-tab-select');
					var href = $this.attr('src') + '?employe_id=' + rowData.employe_id;
					var title = $this.text()+i;
					i++;
					addTab(title, href);
			}
		});
		$('#select_employe').click(function(){
			var row = $('#tt').datagrid('getSelected');
			if(row){
				var $this = $('.cs-navi-tab-select');
				var href = $this.attr('src')+'?employe_id='+row.employe_id;
				var title = $this.text()+i;
				i++;
				addTab(title, href);
			}
			else {
            	$.messager.alert('提示', '请选择员工', 'info');
            }
		})

		$('#edit_employe').click(function(){
			var row = $('#tt').datagrid('getSelected');
			if(row){
				var $this = $('.cs-navi-tab-edit');
				var href = $this.attr('src')+'?employe_id='+row.employe_id;
				var title = $this.text()+j;
				j++;
				addTab(title, href);
			}
			else {
            	$.messager.alert('提示', '请选择员工', 'info');
            }
		})

		$('#del_employe').click(function(){
			var row = $('#tt').datagrid('getSelected');
			
            if(row) {
                $.messager.confirm('提示信息', '是否删除该员工信息?', function(r){
                    if(r){
                        $.ajax({
                        	type:'post',
                            url: '__URL__/delEmploye',
                            data: {employe_id: row.employe_id },
                            success: function (data) {
                            	if(data=='ok'){
                            		$.messager.alert('提示', '删除成功', 'info');
                            		$('#tt').datagrid('reload');
                            	} 
                                if(data=='no'){
                                	$.messager.alert('提示', '删除失败', 'info');
                                }
                            }
                        });
                    }
                });
            }
            else {
            	$.messager.alert('提示', '请选择员工', 'info');
            }
		})

		$('#change_password').click(function(){
			var row = $('#tt').datagrid('getSelected');

			if(row){
				$('#edit_dlg').dialog('open').dialog('setTitle','修改密码');
                $('#efrms').form('clear');
				$('#efrms').form('load',row);
			}
			else {
                $.messager.alert('错误提示', "请选择一个用户", 'error');
            }
		})

		$('#efrms').form({
			url:'__APP__/Employe/changePassword',
		    onSubmit:function(){
		        return $(this).form('validate');
		    },
		    success:function(data){
		    	if(data=='ok'){
		    		$.messager.alert('提醒', '修改成功!', 'info');
		    		$('#frms').datagrid('reload');
                	$('#edit_dlg').dialog('close');
		    	}
		    	if(data=='no'){
		    		$.messager.alert('提醒','修改失败!','info');
		    	}
		    }
		});


	});	


	$.extend($.fn.validatebox.defaults.rules, {
	    
	    mobile: {
        validator: function (value) {
            var reg = /^1[3|4|5|8|9]\d{9}$/;
            return reg.test(value);
        },
        message: '输入手机号码格式不准确.'
       },
	    
	    QQ:{
	        validator: function (value, param) {
	            return /^[1-9]\d{4,10}$/.test(value);
	        },
	        message: 'QQ号码不正确'
	    },
	    equalTo: {
			validator: function (value, param) {
			return value== $(param[0]).val();
			},
			message: '两次输入的字符不一至'
		},
		idcard : {
	        validator : function(value) {
	            return /^\d{15}(\d{2}[A-Za-z0-9])?$/i.test(value);
	        },
	        message : '身份证号码格式不正确'
	    },
	    phone : {
        validator : function(value) {
            return /^((\(\d{2,3}\))|(\d{3}\-))?(\(0\d{2,3}\)|0\d{2,3}-)?[1-9]\d{6,7}(\-\d{1,4})?$/i.test(value);
        },
        message : '格式不正确,请使用下面格式:020-88888888'
    	},
    	integer : {
        validator : function(value) {
            return /^[+]?[0-9]+\d*$/i.test(value);
        },
        message : '请输入数字'
    	},
    	name: {
        validator: function(value){  
                var flag;
                    $.ajax({
                            type: 'POST', 
                            url: '__URL__/check_employe_work_id',
                            data:{employe_work_id:value},
                            async:false,
                            success: function(data) {
                                if(data=='ok') {
                                    flag = true;
                                }else{
                                    flag = false;
                                }
                            }
                     });
                  return flag;
            },
           message: '用户名已存在，请更换！'
        }
	});
</script>

</body>
</html>